package com.wedata.抖音;

import cn.hutool.core.util.URLUtil;
import cn.hutool.http.HtmlUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import com.disdr.utils.DateUtils;
import com.google.gson.Gson;
import com.wedata.HttpUtils;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.*;

public class 抖音抖店会员 {

     private static String uri = "http://localhost:8090";
    //private static String uri = "https://twedata.gymcity.com.cn";
    //private static String uri = "https://wedata.gymcity.com.cn";

    public static void main(String[] args) {

        模拟查询通知();
        //模拟入会通知();
        //模拟退会通知();

    }

    private static void 模拟入会通知(){
        String url = uri + "/datacenter/api/callback/membershipBind?";
        JSONObject body = new JSONObject();

        body.set("open_id","1@#/XcpbcciDKNlEof4bPPT/G4c/NS/UiYJr41YXNNNigV370A0YXGPmNELGNyXe4YWjkLN");
        body.set("shop_id","52256301");
        body.set("mask_mobile","132****3690");
        //body.set("mobile","13290053690");
        body.set("mobile","");

        String param = verifyDyShopMsg(body);
        HttpUtils.sendPost(url+URLUtil.encode(param), null, body);
    }

    private static void 模拟退会通知(){
        String url = uri + "/datacenter/api/callback/membershipUnbind?";
        JSONObject body = new JSONObject();
        body.set("open_id","1@#/XcpbcciDKNlEof4bPPT/G4c/NS/UiYJr41YXNNNigV370A0YXGPmNELGNyXe4YWjkLN");
        body.set("shop_id",52256301);
        body.set("unbind_scene",1);
        body.set("unbind_time","2025-08-27 10:00:00");

        String param = verifyDyShopMsg(body);
        String urlParam = param+"&param_json="+body;
        JSONObject result = HttpUtils.doGet(url+URLUtil.encode(urlParam));
        System.out.println(result);
    }
    private static void 模拟查询通知(){
        String url = uri + "/datacenter/api/callback/membershipBindCheck?";
        JSONObject body = new JSONObject();
        body.set("open_id","1@#/XcpbcciDKNlEof4bPPT/G4c/NS/UiYJr41YXNNNigV370A0YXGPmNELGNyXe4YWjkLN");
        body.set("shop_id","52256301");
        body.set("mask_mobile","132****3690");
        body.set("mobile","13290053690");

        String param = verifyDyShopMsg(body);
        HttpUtils.sendPost(url+URLUtil.encode(param), null, body);
    }

    private static String verifyDyShopMsg(JSONObject bodyMap) {
        String appSecret = "936896f2-1337-41fe-9288-fca8e4aace98";
        String timestamp = DateUtils.dateToString(new Date());

        StringBuffer signStr = new StringBuffer(appSecret+"app_key7166066910138730014");
        signStr.append("param_json"+bodyMap);
        signStr.append("timestamp"+ timestamp);
        signStr.append(appSecret);

        StringBuffer sb = new StringBuffer("app_key=7166066910138730014");
        //sb.append("&param_json="+bodyMap);
        sb.append("&timestamp="+ timestamp);

        System.out.println(signStr);
        String sign = DigestUtils.md5Hex(signStr.toString());
        sb.append("&sign="+sign);


        return sb.toString();
    }

}
